local joy_mou__jijiang = fk.CreateSkill {

  name = "joy_mou__jijiang$",

  tags = {  },

}



joy_mou__jijiang:addEffect(fk.EventPhaseEnd, {
  name = "joy_mou__jijiang$",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(joy_mou__jijiang.name) and player.phase == Player.Play then
      local players = player.room.alive_players
      return #players > 2 and table.find(players, function(p) return p ~= player and p.kingdom == "shu" end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseActiveSkill(player, "joy_mou__jijiang_choose", "#joy_mou__jijiang-promot", true, nil, true)
    if success and dat then
      event:setCostData(self, dat.targets)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local victim = room:getPlayerById(event:getCostData(self)[1])
    local bro = room:getPlayerById(event:getCostData(self)[2])
    room:doIndicate(player.id, {bro.id})
    local choices = {"joy_mou__jijiang_skip"}
    if not bro:prohibitUse(Fk:cloneCard("slash")) and not bro:isProhibited(victim, Fk:cloneCard("slash")) then
      table.insert(choices, 1, "joy_mou__jijiang_slash:"..victim.id)
    end
    if room:askForChoice(bro, choices, joy_mou__jijiang.name) == "joy_mou__jijiang_skip" then
      room:setPlayerMark(bro, "@@joy_mou__jijiang_skip", 1)
    else
      room:useVirtualCard("slash", nil, bro, victim, joy_mou__jijiang.name, true)
    end
  end,
})

joy_mou__jijiang:addEffect(fk.EventPhaseChanging, {
  name = "#joy_mou__jijiang_delay",
  events = {fk.EventPhaseChanging},
  priority = 10,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target:getMark("@@joy_mou__jijiang_skip") > 0 and data.to == Player.Play
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@@joy_mou__jijiang_skip", 0)
    target:skip(Player.Play)
    return true
  end,
})

return joy_mou__jijiang